package com.lfnyxy.common.dto;

/**
 * Created by ted on 17/5/31.
 */
public class ApiResult<T> {

    private long code;
    private T data;
    private String message;

    private ApiResult(T data) {
        this.code = 0;
        this.message = "success";
        this.data = data;
    }

    private ApiResult(CodeMessage cm){
        if(cm != null){
            this.code = cm.getCode();
            this.message = cm.getMessage();
            this.data = null;
        }
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult(data);
    }

    public static <T> ApiResult<T> error(CodeMessage cm){
        return new ApiResult<T>(cm);
    }

    public long getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }
}
